<template>
	<view class="shareholder">
		<commonHeader :title="$t('ois1')"></commonHeader>
		<view class="gHeadbox"></view>
		<view class="shareholderBox">
			<view class="shareholderBox_head">
				<view class="head_name">
					{{$t('ois2')}}（USDT)
				</view>
				<view class="head_num">
					<text class="head_num_money">$</text>
					<text>{{Number(maccount)}}</text>
				</view>
				<!-- 	<view class="congitem">
					{{$t('ois3')}}
				</view> -->
			</view>
			<view class="shareholderBox_money">
				<view class="money_title">
					{{$t('ois4')}}
				</view>
				<view class="money_box">
					<!-- :class="typeiactive == item.id?'money_box_item itemhuis':'money_box_item'" -->
					<view v-for="(item,index) in nodeList" :key="item" @click="ntoactive(item)"
						:class="Number(newamount.teamLevel) < Number(item.needTeamLevel)?'money_box_item itemhui':(typeiactive== item.id?'money_box_item itemhuis':'money_box_item ' )">
						<text class="num">{{item.name}}</text>
						<text
							class="title">（{{item.needTeamLevelName}}{{$t('ois5')}}，{{$t('ois6')}}{{floatNum(Number(item.jumpPrice),2,Number(item.needJump))}}U,{{$t('ois7')}}{{Number(item.needJump)}}JUMP）</text>
					</view>
				</view>
			</view>
			<view class="shareholderBox_info">
				<view class="info_title">
					<text class="lang"></text>
					<text>{{$t('ois8')}}</text>
				</view>
				<view class="info_content">
					<view class="">
						<text>{{$t('ois9')}}</text>
						<text class="timres">08:00-24:00</text>
					</view>
					<view class="">
						{{$t('ois10')}}
					</view>
					<view class="">
						{{$t('ois11')}}
					</view>
				</view>
			</view>
			<view class="shareholderBox_pwd">
				<input type="password" v-model="password" :placeholder="$t('ois12')" />
			</view>
			<view class="shareholderBox_btn" @click="fnMActivate">
				{{$t('ois13')}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		memberAccount, //用户资产
		nodeList, //股东列表
		pnodeList, //成为股东
		memberTeamInfo, //社区信息
	} from '@/api/home.js'
	export default {
		data() {
			return {
				maccount: '', // 用户资产-usdt
				nodeList: '', //股东列表
				typeiactive: 0, //激活选择金额
				password: '', //密码
				newamount: '', //社区信息
			}
		},
		mounted() {
			this.fnmemberAccount() // 用户资产
			this.fnnodeList() //股东列表
			this.fnmemberTeamInfo() //社区信息
		},
		methods: {
			floatNum(f, d, n) {
				let m = Math.pow(10, d);
				let num = (Math.round(f * m) * n) / m;
				return num;
			},

			// 社区信息
			fnmemberTeamInfo() {
				var params = {
					address: this.$store.state.devAddress
				}
				memberTeamInfo(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.newamount = res.data
					}
				})
			},
			// 股东列表
			fnnodeList() {
				nodeList().then(res => {
					console.log(res)
					if (res.code == 200) {
						this.nodeList = res.data;
						// this.typeiactive = res.data[0].id
					}
				})
			},
			// 用户资产
			fnmemberAccount() {
				var params = {
					address: this.$store.state.devAddress
				}
				memberAccount(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.maccount = res.data.usdt
					}
				})
			},
			// 激活
			fnMActivate() {
				if (!this.typeiactive) {
					uni.showToast({
						icon: 'error',
						title: this.$t('ois14'),
					})
					return;
				}
				if (!this.password) {
					uni.showToast({
						icon: 'error',
						title: this.$t('ois15'),
					})
					return;
				}
				var params = {
					address: this.$store.state.devAddress,
					password: this.password,
					nodeId: this.typeiactive,
				}
				pnodeList(params).then(res => {
					console.log(res)
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: res.msg,
						})
						setTimeout(() => {
							console.log('888')
							// 返回上一页并发送事件通知
							uni.navigateBack({
								delta: 1, // 返回的页面数，如果需要返回上一页，delta 设为 1
								success: function() {
									// 通过 eventChannel 向上一页发送事件
									let pages = getCurrentPages();
									let prevPage = pages[pages.length - 2];
									prevPage.$vm.triggerRefresh();
								}
							});
						}, 2000)

					} else {
						uni.showToast({
							icon: 'error',
							title: res.msg,
						})
					}

				})
			},
			// 激活选择
			ntoactive(tpinfo) {
				if (Number(this.newamount.teamLevel) >= Number(tpinfo.needTeamLevel)) {
					this.typeiactive = tpinfo.id
				}

			},
			// 乘100
			floatNum(f, d, n) {
				let m = Math.pow(10, d);
				let num = (Math.round(f * m) * n) / m;
				return num;
			}
		},

	}
</script>

<style scoped lang="scss">
	.shareholderBox {
		padding: 30rpx;
		box-sizing: border-box;

		&_head {
			background: url('@/static/img/gd.png') no-repeat;
			background-size: cover;
			width: 100%;
			height: 223rpx;
			padding: 20rpx 40rpx;
			box-sizing: border-box;
			position: relative;

			.head_name {
				color: #ffffff;
				font-size: 30rpx;
				font-weight: 500;
				margin-bottom: 24rpx;
			}

			.head_num {
				color: #ffffff;
				font-size: 50rpx;
				display: flex;
				align-items: center;

				&_money {
					color: #ffffff;
					font-size: 32rpx;
					margin-right: 20rpx;
				}
			}

			.congitem {
				position: absolute;
				right: 0;
				width: 170rpx;
				height: 56rpx;
				line-height: 56rpx;
				border-radius: 28rpx 0 0 28rpx;
				opacity: 1;
				border: 2rpx solid #979797;
				background: #d6a7f9;
				top: 35rpx;
				color: #2c3346;
				font-size: 30rpx;
				text-align: center;
			}
		}

		&_money {
			margin-top: 35rpx;

			.money_title {
				width: 280rpx;
				height: 68rpx;
				line-height: 68rpx;
				background: url("@/static/img/j_zhiya.png") no-repeat;
				background-size: cover;
				color: #eccdff;
				font-size: 40rpx;
				text-align: left;
				box-sizing: border-box;
				padding-left: 40rpx;
				margin-bottom: 34rpx;
			}

			.money_box {
				.itemhui {
					background: #979797 !important;
				}

				.itemhuis {
					background: linear-gradient(137deg, #7E06FA 0%, #6300c042 100%) !important;
					box-shadow: inset 0 2rpx 6rpx 0 #ffffff, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 20rpx 0 #00000038;
				}

				&_item {
					width: 100%;
					height: 86rpx;
					border-radius: 96rpx;
					opacity: 1;
					background: linear-gradient(137deg, #65008275 0%, #6300c042 100%);
					box-shadow: inset 0 2rpx 6rpx 0 #4545458a, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 20rpx 0 #00000038;
					margin-bottom: 38rpx;
					padding: 12rpx 20rpx;
					box-sizing: border-box;
					color: #eccdff;
					font-size: 24rpx;
					font-weight: 400;
					display: flex;
					align-items: center;
					justify-content: center;

					.num {
						background-image: linear-gradient(to right, #E474FF, #F1B8FF);
						background-clip: text;
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
						font-size: 32rpx;
						font-weight: 700;

					}
				}
			}
		}

		&_info {
			.info_title {
				display: flex;
				align-items: center;
				color: #d6a7f9;
				font-size: 30rpx;
				margin-bottom: 18rpx;

				.lang {
					width: 6rpx;
					height: 30rpx;
					opacity: 1;
					border: 2rpx solid #d6a7f9;
					background: linear-gradient(-16.5deg, #f1b8ff 0%, #e474ff 100%);
					box-sizing: border-box;
					margin-right: 10rpx;
				}
			}

			.info_content {
				color: #b6b6b6;
				font-size: 28rpx;
				line-height: 50rpx;

				.timres {
					color: #D6A7F9;
				}
			}
		}

		&_pwd {
			width: 100%;
			height: 108rpx;
			border-radius: 24rpx;
			opacity: 1;
			border: 2rpx solid #979797;
			background: linear-gradient(137deg, #65008275 0%, #20005e63 100%);
			box-shadow: inset 0 2rpx 6rpx 0 #4545458a, inset 0 0 16rpx 0 #ffffff3b, 4rpx 4rpx 2r0px 0 #00000038;
			margin-top: 28rpx;
			padding: 30rpx;
			box-sizing: border-box;

			input {
				font-size: 28rpx;
				border-bottom: 2rpx solid #b1b1b2;
				height: 50rpx;
				line-height: 50rpx;

				&::placeholder {
					color: #b6b6b6;
				}
			}
		}

		&_btn {
			background: url("@/static/img/w.png") no-repeat;
			background-size: contain;
			width: 572rpx;
			height: 78rpx;
			line-height: 78rpx;
			text-align: center;
			color: #ffffff;
			font-size: 42rpx;
			font-weight: 500;
			margin: 50rpx auto;
		}
	}
</style>